﻿using HQHS.Library.DAL.Menu.Sprocs;
using HQHS.Library.DAO.Menu;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HQHS.Library.DAL.Menu
{
    public class MenuMgr
    {
        public static IList<MenuInfo> GetMenus_ByType(byte? menuType)
        {
            using (Menu_LoadByType_p cmd = new Menu_LoadByType_p())
            {
                cmd.Parameters.Type = menuType;
                using (GOTSqlConnectionManager cm = new GOTSqlConnectionManager())
                {
                    using (SqlDataReader reader = cm.ExecuteReader(cmd))
                    {
                        return MenuInfoAssembler.CreateList(reader);
                    }
                }
            }
        }
        public static int Save(MenuInfo info)
        {
            using (Menu_Save_p cmd = new Menu_Save_p())
            {
                cmd.Parameters.Mennu_id = info.ID;
                cmd.Parameters.Name = info.Name;
                cmd.Parameters.Link = info.Link;
                cmd.Parameters.Type = info.Type;
                cmd.Parameters.DisplayOrder = info.DisplayOrder;
                cmd.Parameters.ParentId = info.ParentId;
                cmd.Parameters.InsertedBy = info.InsertedBy;
                cmd.Parameters.UpdatedBy = info.UpdatedBy;
                using (GOTSqlConnectionManager cm = new GOTSqlConnectionManager())
                {
                    cm.ExecuteNonQuery(cmd);
                    return cmd.Parameters.Mennu_id;
                }
            }
        }
    }
}
